package moodish.client;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


import moodish.server.ServerMain;

/**
 * The Main menu to start client windows as the server. 
 * Each time is needed a client, the user must choose a New Client Window
 * 
 * @author Miguel, Luis e Ricardo
 * @version 1 
 *
 */



public class StartMoodish implements Runnable{
	
	
	private static String ServerORClient = "";
	public void run() {
		if (ServerORClient == "Server"){
			ServerMain.main(null);
			JOptionPane.showMessageDialog(null, "The Server was Started!");
		}
			else {
				ClientGUI newClientGUI= new ClientGUI();
				newClientGUI.main(null);
				ClientGUI newClientGUI2= new ClientGUI();
				newClientGUI2.main(null);
		}
		
		
	}
	
	
	// Global data

	
	
	private static JPanel actionPanel_n = new JPanel();
	
	private static JFrame guiFrame = new JFrame();

	

	public static void main(String[] args) {
		
	
		
		// GUI construction
		guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		guiFrame.setTitle("Moodish Main Menu - Asterisk");
		guiFrame.setSize(620, 200);
		guiFrame.setLocationRelativeTo(null);
		guiFrame.add(actionPanel_n, BorderLayout.CENTER);
				
		
			
		
		// options button
		JButton btnNewClientWindow = new JButton("Start New Client Window");
		JButton btnStarServer = new JButton("Start Server");
	
		actionPanel_n.add(btnNewClientWindow);
		actionPanel_n.add(btnStarServer);
	

		btnNewClientWindow.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ServerORClient = "Client";
				(new Thread(new StartMoodish())).start();
			}
		});

		btnStarServer.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ServerORClient = "Server";
				(new Thread(new StartMoodish())).start();
			}
		});

		
		
		
		guiFrame.setVisible(true);
		
		
	}
}